class Pokers {
  constructor() {
    this.points = ['7', 'joker', '5', '2', '3', 'a', 'k', 'q', 'j', '10', '9', '8', '6', '4']; //牌面
    this.types = ['s', 'h', 'c', 'd']; //牌色
    this.pokers = []; //扑克牌
    this.size = 55; //牌大小
    this.init(); //生成扑克牌
  }
  // 初始化牌
  init() {
    // ES6写法
    this.points.forEach((v, i) => {
      // 判断如果是大小王只能由两种颜色
      v == 'joker' ? this.types = ['s', 'h'] : this.types = ['s', 'h', 'c', 'd']
      let integral = 0;
      (v == '10' || v == 'k') && (integral = 10);
      v == '5' && (integral = 5);
      this.types.forEach((t, j) => {
        let item = {};
        this.size--;
        item.name = t + v; //牌名
        item.point = v; //牌面
        item.size = this.size; //牌大小
        item.types = t; //牌色
        item.integral = integral; //积分
        this.pokers.push(item);
      })
    })
  }
  // 洗牌
  upset(pokers) {
    pokers = pokers || this.pokers;

    pokers.sort(function () {
      return Math.random() - 0.5; //随机排序
    });
    return pokers;
  }
  // 发牌
  sysLicensing(number,flag,pokers){
    pokers = pokers || this.pokers; //传牌
    number = number || 1; //切几张
    flag = flag || false; //是否洗牌

    if(flag){
      return this.upset(pokers).splice(0,number);
    }
    return pokers.splice(0,number);
  }
  // 牌面比较
}

module.exports = Pokers;

/*
  Pokers 类/对象：
    内置自动生成扑克牌数组
    API:
      upset(pokers) 洗牌  
        pokers：扑克牌，默认为对象内的扑克牌
      licensing(number,flag,pokers) 发牌  
        number: 发牌数，默认一张
        flag: 是否洗牌，默认不洗牌
        pokers: 扑克牌，默认对象内的扑克牌
*/